package org.example.jvm.classloader;

public class ClassLoaderDemo {
  public static void main(String[] args) throws Exception {
    MyClassLoader2 mc = new MyClassLoader2();
    Class cls = mc.findClass("org.example.jvm.classloader.ClassLoaderTest1");
    Object o = cls.newInstance();
    System.err.println("toString:"+o+","+o.getClass().getClassLoader());
    //直接使用peron是 AppClassLoader
    System.err.println(">>:"+ClassLoaderTest1.class.getClassLoader());
    //由于o是由mc加载的。而Person是由App加载的，所有不可以转换＝来自于两个不同的加载器
    //Person p = (Person) o;//类型转换错误ClassCastException
    //System.err.println(p);
  }
}